<html>
<head><meta charset="utf-8"><title>ManuallyDrop in MaybeUninit · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html">ManuallyDrop in MaybeUninit</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="170411477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411477">(Jul 08 2019 at 23:43)</a>:</h4>
<p>I wonder why is there ManuallyDrop in MaybeUninit?</p>



<a name="170411554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411554">(Jul 08 2019 at 23:44)</a>:</h4>
<p><a href="https://doc.rust-lang.org/stable/src/core/mem.rs.html#1081-1084" target="_blank" title="https://doc.rust-lang.org/stable/src/core/mem.rs.html#1081-1084">https://doc.rust-lang.org/stable/src/core/mem.rs.html#1081-1084</a><br>
Why is it ManuallyDrop? I've thought that Drop is never called for unions?</p>



<a name="170411563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411563">(Jul 08 2019 at 23:44)</a>:</h4>
<p>Is the ManuallyDrop needed for anything safety related?</p>



<a name="170411739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411739">(Jul 08 2019 at 23:48)</a>:</h4>
<p><a href="https://rust-lang.github.io/rfcs/2514-union-initialization-and-drop.html" target="_blank" title="https://rust-lang.github.io/rfcs/2514-union-initialization-and-drop.html">https://rust-lang.github.io/rfcs/2514-union-initialization-and-drop.html</a></p>



<a name="170411886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411886">(Jul 08 2019 at 23:51)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> so drop is called after all?</p>



<a name="170411944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411944">(Jul 08 2019 at 23:52)</a>:</h4>
<p>Oh so it's not meant for safety, but for forward compatibility?</p>



<a name="170411950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411950">(Jul 08 2019 at 23:52)</a>:</h4>
<p>For a possible future where that RFC is implemented and stabilized</p>



<a name="170411978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411978">(Jul 08 2019 at 23:53)</a>:</h4>
<p>As then e.g. MaybeUninit&lt;Vec&lt;u32&gt;&gt; would not be allowed any more?</p>



<a name="170411983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170411983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170411983">(Jul 08 2019 at 23:53)</a>:</h4>
<p>No</p>



<a name="170412052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412052">(Jul 08 2019 at 23:54)</a>:</h4>
<p>The point of disallowing union fields with drop glue is so we never have to worry about what that means and can simply never call drop union fields without that being a massive surprise and footgun</p>



<a name="170412117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412117">(Jul 08 2019 at 23:55)</a>:</h4>
<p>Ok</p>



<a name="170412180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412180">(Jul 08 2019 at 23:56)</a>:</h4>
<p>but that doesn't answer my question: Is the presence of ManuallyDrop is for forwards compatibility only, to keep MaybeUninit&lt;Vec&lt;u32&gt;&gt; working even after the RFC is implemented?</p>



<a name="170412286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412286">(Jul 08 2019 at 23:59)</a>:</h4>
<p>I guess it's yes.</p>



<a name="170412359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412359">(Jul 09 2019 at 00:00)</a>:</h4>
<p>Oh I guess if it's not implemented yet, then it's technically for forward compatibility yes</p>



<a name="170412374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412374">(Jul 09 2019 at 00:00)</a>:</h4>
<p>Sorry for misunderstanding</p>



<a name="170412394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170412394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> est31 <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170412394">(Jul 09 2019 at 00:01)</a>:</h4>
<p>Thanks, that's what I wanted to know!</p>



<a name="170643330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170643330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170643330">(Jul 11 2019 at 15:21)</a>:</h4>
<p><code>ManuallyDrop</code> is not just for compatibility</p>



<a name="170643355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170643355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170643355">(Jul 11 2019 at 15:21)</a>:</h4>
<p>e.g. <code>ManuallyDrop</code> works with unsized types. And <code>Option&lt;ManuallyDrop&lt;Vec&lt;u8&gt;&gt;&gt;</code> gets layout optimizations</p>



<a name="170643411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170643411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170643411">(Jul 11 2019 at 15:22)</a>:</h4>
<p>"I may have totally uninitialized data" vs "I want to control dropping" are not the same concerns</p>



<a name="170643431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop%20in%20MaybeUninit/near/170643431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/ManuallyDrop.20in.20MaybeUninit.html#170643431">(Jul 11 2019 at 15:22)</a>:</h4>
<p>having uninitialized data implies you need to control dropping (hence <code>MaybeUninit</code> does not auto-drp), but not vice versa</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>